package com.ruoyi.information.service.back.impl;

import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.information.domain.back.SysUserBack;
import com.ruoyi.information.domain.back.UserReserveParkBack;
import com.ruoyi.information.mapper.back.SysUserBackMapper;
import com.ruoyi.information.mapper.back.UserReserveParkBackMapper;
import com.ruoyi.information.service.back.IUserReserveParkBackService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * 预选产品Service业务层处理
 *
 * @author ruoyi
 * @date 2023-05-09
 */
@Service
public class UserReserveParkBackServiceImpl implements IUserReserveParkBackService {
    @Autowired
    private UserReserveParkBackMapper userReserveParkMapper;
    @Autowired
    private SysUserBackMapper sysUserMapper;

    /**
     * 查询预选产品
     *
     * @param id 预选产品主键
     * @return 预选产品
     */
    @Override
    public UserReserveParkBack selectUserReserveParkById(Long id) {
        return userReserveParkMapper.selectUserReserveParkById(id);
    }

    /**
     * 查询预选产品列表
     *
     * @param userReservePark 预选产品
     * @return 预选产品
     */
    @Override
    public List<UserReserveParkBack> selectUserReserveParkList(UserReserveParkBack userReservePark) {
        if (userReservePark.getProvince() != null || userReservePark.getNickName() != null || userReservePark.getEconomic() != null) {
            SysUserBack sysUser = new SysUserBack();
            BeanUtils.copyProperties(userReservePark, sysUser);
            List<Long> userIds = sysUserMapper.selectSysUserListBy(sysUser);
            if (userIds == null || userIds.size()==0) {
                return new ArrayList<>();
            }
            userReservePark.setUserIds(userIds);
        }
        return userReserveParkMapper.selectUserReserveParkList(userReservePark);
    }

    /**
     * 新增预选产品
     *
     * @param userReservePark 预选产品
     * @return 结果
     */
    @Override
    public int insertUserReservePark(UserReserveParkBack userReservePark) {
        userReservePark.setCreateTime(DateUtils.getNowDate());
        return userReserveParkMapper.insertUserReservePark(userReservePark);
    }

    /**
     * 修改预选产品
     *
     * @param userReservePark 预选产品
     * @return 结果
     */
    @Override
    public int updateUserReservePark(UserReserveParkBack userReservePark) {
        userReservePark.setUpdateTime(DateUtils.getNowDate());
        return userReserveParkMapper.updateUserReservePark(userReservePark);
    }

    /**
     * 批量删除预选产品
     *
     * @param ids 需要删除的预选产品主键
     * @return 结果
     */
    @Override
    public int deleteUserReserveParkByIds(Long[] ids) {
        return userReserveParkMapper.deleteUserReserveParkByIds(ids);
    }

    /**
     * 删除预选产品信息
     *
     * @param id 预选产品主键
     * @return 结果
     */
    @Override
    public int deleteUserReserveParkById(Long id) {
        return userReserveParkMapper.deleteUserReserveParkById(id);
    }
}
